The screen is a 240x160 window onto a world that can be much bigger, and the camera decides which part of that world the window shows.
The GBA screen is 240 pixels wide and 160 tall. That is small, and a room is usually much larger. A room's size in pixels is room_width() by room_height(). So the screen shows only a part of the room at any moment, and the camera decides which part.
Every position in the game is a world position: x and y measured from the top-left corner of the room, where (0, 0) is. An instance at world (100, 0) is 100 pixels right of the room's left edge, on the room's top edge, whether or not the camera is looking there. The camera has a world position too. It is the world point where the view begins: the top-left corner of what the screen shows. With the camera at (0, 0), the screen shows the world from x = 0 to 240 and y = 0 to 160. A room the size of the screen shows exactly with the default camera. (Something at world (x, y) appears on the screen at (x - camera_x(), y - camera_y()).)
Move the camera and everything in the world slides across the screen together: instances, room tiles, backgrounds and text drawn with draw_text. Things that are drawn fixed to the screen do not move. That covers everything drawn in a Draw GUI event, and the _anchored drawing functions. This is how a health bar stays in its corner while the room scrolls behind it.
Nothing follows anything until you say so. camera_follow(target) makes the camera follow one instance, usually the player:
// Create event of the player
camera_follow(self);Following is eased. The camera does not lock onto the target. Each frame it closes part of the gap between where it is and where the target is, so it trails a little behind and settles when the target stops. That looks smooth and it is the usual feel for a game.
camera_follow_ease(x_factor, y_factor) sets how tight the follow is, separately for each axis. The default is 0.08 on both, which takes a little under half a second to mostly catch up. A value of 1 means no lag at all: the camera shows the target's exact position every frame. The value must be above 0 and at most 1. 0 would freeze the camera, so it is refused. The setting is kept until you change it, whoever is being followed.camera_snap() jumps to the followed target at once, with no easing, and keeps following. Use it just after placing the player somewhere new, so the camera does not slowly glide over from the old place. A room change does this for you.camera_unfollow() stops following. The camera stays exactly where it is until you set it or follow again. If the followed instance is destroyed, the camera also stays where it last was.The easing is done in whole pixels on purpose. A moving sprite and the camera each round to a whole pixel, and easing a fractional camera position makes moving sprites shimmer by one pixel every frame. The engine avoids that, so you do not need to.
Three more settings change how the followed camera sits on its target. All three are whole pixels, all three start at 0 (which is how the camera has always been), and all three stay until you change them.
camera_dead_zone(width, height) is a box in the middle of the screen. The target can move around inside it and the camera stays perfectly still. When the target walks out of the box, the camera moves just enough to keep it on the edge. It stops small steps from shaking the whole picture.camera_look_ahead(distance, speed) makes the camera look distance pixels in front of the way the target is walking, and swing across at speed pixels a frame when it turns round. The player sees more of where they are going.camera_offset(x, y) simply shifts the middle of the view away from the target, so a hero can sit low on the screen, or to the left of it.Picture the camera looking at a spot. The offset and the look-ahead move that spot away from the target. The dead zone decides whether the camera bothers to follow it when the spot moves a little. Ease (see above) decides how quickly it catches up once it does.
You do not have to write any of this. Room Properties has a Camera section (and a world has the same section in World Properties), with a row for each thing on this page:
| Row | What it does |
|---|---|
| Follows | who the camera follows from the start. A world starts on its player |
| Stops at edges | keeps the screen from showing past the room's edge (this is the same tickbox that used to be in Transitions and Values) |
| Ease | how tightly it follows, from soft to tight. The last notch is no lag. Tick "Ease up/down separately" to give the vertical its own slider |
| Dead zone | the box, width and height |
| Look-ahead | the distance, and how fast it swings when the player turns round |
| Offset | across and down |
| Snap on arrival | whether the camera jumps to its target when the room starts (the normal way), or eases there from where it was |
The settings are applied when the room starts, before anything in your code runs. That is the whole rule for how the panel and your code get along: code always wins. If a Create event says camera_follow(self) or camera_dead_zone(0, 0), that call happens after the panel did its part, so it changes the camera and the panel does not undo it. A room that sets nothing in the panel leaves the camera alone, so a game written entirely in code plays exactly as it did before the panel existed.
A room that sets anything in its Camera section starts with all of it: whatever you left alone is the normal value (ease 0.08, no dead zone, no look-ahead, no offset, snap on), not what the last room happened to leave behind. A room that sets nothing leaves the camera as it finds it.
In a world, the settings are applied once, when the world is entered. Walking from one part of the world into the next never restarts them, and never undoes what your code set in the meantime.
camera_set(x, y) stops following and puts the top-left corner of the view at that world point at once. It suits a fixed shot: looking at a door before a cutscene, or a boss arena's center. The point you give is the top-left corner of the view, so to put a point (cx, cy) in the middle of the screen, subtract half a screen:
// Step event of a boss arena's door, once the player is inside
camera_set(160 - screen_width() / 2, 120 - screen_height() / 2); // centre the view on (160, 120)camera_x() and camera_y() read where the view begins now.
You normally do not want the screen to show the empty space past a room's edge. Bounds are a rectangle the camera is not allowed to leave. When a room loads, the bounds are set for you: the view may begin anywhere from the room's top-left corner (0, 0) to (room_width() - screen_width(), room_height() - screen_height()), so the screen edge stops at the room edge. A room smaller than the screen is shown centered on it: the camera is pulled back inside the bounds whenever a room loads, and in that case camera_x() can be below 0. A room can also be set not to clamp the camera at all.
camera_bounds(left, top, right, bottom) sets your own rectangle. Like camera_set, it counts where the view begins (its top-left corner), which is why the right and bottom limits are pulled in by a whole screen from the room's far edges.camera_bounds_clear() removes the limit.Bounds apply to a followed camera and to camera_set.
camera_shake(power, frames) adds a random jitter of up to power pixels, fading to nothing over frames frames. It is for impacts and explosions. The jitter is a jolt on top of the normal camera position, so following carries on normally underneath it. A power or frames of 0 or less stops a shake at once.
// Step event of a boss that slams the ground
if (btn_pressed(BTN_B)) {
camera_shake(4, 20); // up to 4 pixels of jitter, fading out over 20 frames
}| Entry | What it is |
|---|---|
camera_follow, camera_unfollow | start and stop following an instance |
camera_follow_ease | how tightly it follows |
camera_dead_zone, camera_look_ahead, camera_offset | a box the target can move in, looking ahead of it, and shifting the middle of the view |
camera_snap | jump to the target now |
camera_set | place it at a point |
camera_bounds, camera_bounds_clear | the rectangle it may not leave |
camera_x, camera_y | where it is |
camera_shake | a temporary jolt |
There is one camera for the whole game, so the settings above are global and not per room. Each room load sets the bounds again, applies the room's Camera section (if it sets anything) and snaps the camera to whatever it is following. Rooms covers the rest of what a room load does.
camera_follow_ease, and the tightest setting, 1, is no lag at all. It always trails by a share of the gap, never by a fixed distance. You can lead the target with camera_look_ahead, or hold it still while the target moves a little with camera_dead_zone.draw_rect_fill, say). (A zoomable background is the one exception: it is fixed to the screen, and you place it with screen numbers.)